/**
 * 
 */
package com.zxc.redis;

import java.util.List;

import cn.hutool.core.collection.CollectionUtil;


/**
 * @author Administrator
 *
 */
public class RedisDemo {

	public static void main(String[] args) {
		JedisUtil.init();
		JedisUtil jedis = JedisUtil.getInstance();
//		long count = jedis.LISTS.lpush("list_key", "1");
//		System.out.println("list.size="+count);
//		count = jedis.LISTS.lpush("list_key", "2");
//		System.out.println("list.size="+count);
//		count = jedis.LISTS.lpush("list_key", "3");
//		System.out.println("list.size="+count);
//		count = jedis.LISTS.llen("list_key");
//		List<String> list = jedis.LISTS.lrange("list_key", 0, count);
//		System.out.println(CollectionUtil.join(list, ","));
		
		
		TokenBucket tokenBucket = new TokenBucket(jedis.getPool());

        String key = "my_rate_limiter";
        int rate = 10; // 每秒生成10个令牌
        int capacity = 200; // 令牌桶的容量
        int requested = 1; // 每次请求消耗1个令牌

        boolean allowed = tokenBucket.acquireToken(key, rate, capacity, requested);
        if (allowed) {
            System.out.println("Request allowed");
        } else {
            System.out.println("Request denied");
        }

	}
}
